#ifndef METESTATION_H
#define METESTATION_H

#include <QObject>
#include <QDate>
#include <QTime>

#include <QtSerialPort/QSerialPort>

//extern const int METESTATION_PROTOCOLALL_LENGTH;

#define METESTATION_PROTOCOLALL_LENGTH 136

class MeteStationProtocolAll{
public:
    QDate date;
    QTime time;
    double temperature;
    double humidity;
    double pressure;
    double one_minute_maxWindSpeed;
    double one_minute_windDirection;
    double two_minute_avgWindSpeed;
    double two_minute_avgWindDirection;
    double ten_minute_avgWindSpeed;
    double ten_minute_avgWindDirection;
    double minute_precipitation;
    double hour_precipitation;
    double aux_minute_precipitation;
    double aux_hour_precipitation;
    double road_temerature;
    double atmosphere_electric_field;
    double total_solar_radiation;
    double dew_point_temperature;
    double water_vapor_pressure;
    double voltage;
    int electricity_quantity;
    double tilt_angle;

};

//地面气象站解析类
class MeteStation: public QObject
{
    Q_OBJECT
public:

    QSerialPort* m_port;
    QByteArray m_readBuffer;

    static MeteStation* getInstance();
    bool openDevice(QString portName);
    void closedevice();

    ~MeteStation();

    signals:
    //VisibilityProtocol类中保存从协议中解析出来的数据。持有Visibility对象的界面在初始化时，将此信号和一个更新界面的函数进行连接即可
    void updateView(const MeteStationProtocolAll& protocol);
    //解析命令的信号，QByteArray为协议格式的数据，在构造函数时connect信号和一个解析协议的lambda函数，函数完成解析后发出updateView信号
    void protocol(QByteArray);

private:
    MeteStation(QObject* parent = nullptr);
    static MeteStation* instance;
};

#endif // METESTATION_H
